#ifndef UI_H
#define UI_H

#include <gtkmm.h>
#include <functional>
#include <thread>

class UI
{
  public:
    UI();
    virtual ~UI();
    void Boot();
    std::function<void(const std::string& proj_name,const std::string& list_file)> funcPage1Ready;
    std::function<std::tuple<std::string,long,std::string>()> funcGetNextPeople;
    std::function<std::tuple<std::string,long,std::string>()> funcGetLastPeople;
    std::function<std::tuple<std::string,long,std::string>()> funcGetCurrentPeople;
    std::function<void(std::string)> funcSetServerIPAddr;
    //                       录制名称    录制类型    已经录制 总录制
    std::function<std::tuple<std::string,std::string,long,long>()> funcGetRecordInfo;
    std::function<void(bool)> funcRecordControl;
    std::function<long()> funcGetAllRecord;

  private:
    template<class T> T* GetInstance(const char* name);
    template<class T> T* GetInstancePlus(T* type,const char* name);
    Glib::RefPtr<Gtk::Builder> refBuilder;
    Gtk::Entry* entryProjectName;
    Gtk::Button* btnLastPeople;
    Gtk::Button* btnNextPeople;
    Gtk::Label* labCurrentName;
    Gtk::Label* labCurrentID;
    Gtk::Label* labCurrentSex;
    Gtk::Label* labTaskName;
    Gtk::Label* labType;
    Gtk::Label* labRecordSreial;
    Gtk::Entry* entryServerAddr;
    Gtk::ProgressBar* progRecordSreial;
    Gtk::Button* btnRecordControl;
    Gtk::Label* labRecordInf;
    Gtk::Assistant* mainWindow;
    Gtk::Button* btnChooseRecordList;
    Gtk::Entry* entryRecordList;
    Glib::RefPtr<Gtk::Application> app;
    Gtk::Label* labRecordStatics;

    void signal_cancel_assistant();
    void signal_apply_assistant();
    void signal_changed_elabProjectName();
    void signal_click_btnChooseRecordList();
    void signal_finish_ChooseRecord(const Glib::RefPtr<Gio::AsyncResult>& result,const Glib::RefPtr<Gtk::FileDialog>& dialog);
    void signal_click_btnNextPeople();
    void signal_click_btnLastPeople();
    void signal_click_btnRecordControl();
    void signal_close_assistant();
    void signal_changed_entryServerAddr();
    friend void CheckPage2Ready(UI* ptr);
    friend void UpdateRecordInf(UI* ptr);
    friend void UpdateStudentInf(UI* ptr,std::function<std::tuple<std::string,long,std::string>()> func);

    std::jthread timerThread;
    Glib::Dispatcher patcher;
    void signal_notification_patcher();
    std::chrono::steady_clock::time_point startTime;

};

#endif
